package org.boot.chat.controller;

import org.boot.chat.core.EasyChatUtil;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;


/**
 * 请求ai - controller 示例
 * @author 最爱芫荽
 * @email 15733440205@163.com
 */
@RestController
@RequestMapping("/easyChat")
public class ChatController {

    @CrossOrigin
    @GetMapping("/ask")
    public String ask(@RequestParam(value = "model", required = false) String model,
                      @RequestParam("message") String message) {
        return EasyChatUtil.call(model, message);
    }

    @CrossOrigin
    @GetMapping(value = "/askStream", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<String> askStream(@RequestParam(value = "model", required = false) String model,
                                  @RequestParam("message") String message) {
        return EasyChatUtil.chatModel(model).stream(message);
    }
}
